from app import db


class Link(db.Model):
    __tablename__ = 'cms_link'
    link_pk = db.Column(db.Integer,primary_key=True)
    link_title = db.Column(db.String)
    link_images = db.Column(db.String)
    link_address = db.Column(db.String)
    link_remarks = db.Column(db.String)


    def __repr__(self):
        return '<Link %r>' % self.link_pk
        
    #将查询出的list数据转换为字典，否则无法序列化
    def to_dict(items):
        lic = []
        for item in items:
            lic.append(
                {
                    'link_pk': item.link_pk,
                    'link_title': item.link_title,
                    'link_images': item.link_images,
                    'link_address': item.link_address,
                    'link_remarks': item.link_remarks
                }
            )
        return lic